<?php
/**
 * @Author:      lyt
 * @DateTime:  2017-07-28 09:59:36
 * @Description: 套餐卡订单支付记录
 */
class ServiceCardOrderPayRecord extends Eloquent
{
    protected $table = "service_card_order_pay_record";
    public static $pay_pay_type=array(
        "1"=>"线下支付现金",
        "2"=>"支付宝",
        "3"=>"微信",
        "5"=>"其他",
        '6'=>'线下支付挂单',
        "7"=>"刷卡",
        '8'=>'余额支付',
        '11'=>'线下支票',
        '20'=>'智能pos',
    );

    public static $pay_pay_type_source=array(
        "1"=>array(1,2),
        "2"=>array(1,2),
        "3"=>array(1,2),
        "5"=>array(1),
        '6'=>array(1),
        "7"=>array(1,2),
        '8'=>array(1),
        '11'=>array(1),
        '20'=>array(2),
    );

    public static $ei_pay_type=array(1,2,3,7,8,11);

    /**
     * @Author:      lyt
     * @DateTime:  2017-07-31 10:27:58
     * @Description: 套餐卡订单支付新接口
     * 方法内部不对传参验证 请保证传参正确
     */
    public static function order_pay($order_id,$pay_type,$pay_amount,$sc_user_id,$create_type,$driver_id,$source=1){
      return DB::transaction(function () use ($order_id,$pay_type,$pay_amount,$sc_user_id,$create_type,$driver_id,$source) {
        $order = ServiceCardOrder::where("order_id",$order_id)->lockForUpdate()->first();
        if(in_array($order->status,array(1117,1217,1417))){//是否已结算
          DB::rollback();
          $response = Lang::get("scs_error.order_status_error_40040");
          return $response;
        }
        $temp_pay=ServiceCardOrderPayRecord::where("order_id",$order->order_id)->whereIn("status",array(1,5,7))->where("pay_type",$pay_type)->first();
        if($temp_pay){
          DB::rollback();
          $response = Lang::get("scs_error.order_pay_record_40131");
          return $response;
        }
        $order_amount=$pay_amount*100;
        $temp_amount=ServiceCardOrderPayRecord::where("order_id",$order->order_id)->whereIn("status",array(0,5,7))->sum("amount");
        if(bcsub($order->amount, $order->pay_amount,0)<($order_amount+$temp_amount)){
          DB::rollback();
          $response = Lang::get("scs_error.order_pay_record_40113");
          return $response;
        }
        $user = Users::find($order->user_id);
        $tran_no = date('YmdHis',time()).Common::generateCode(8);
        if($user->id == 1000000000 && $pay_type == 8){//特殊账户不能余额
            DB::rollback();
            $response = Lang::get("scs_error.order_user_notpay_40059");
            return $response;
        }
        //各种进行判断
        if($user->type == 1 && $pay_type== 6){//如果是个人用户不能用挂账
          DB::rollback();
          $response = Lang::get("scs_error.order_user_notpay_40038");
          return $response;
        }
        //验证完成订单支付
        $o_p=new ServiceCardOrderPayRecord;
        $o_p->user_id=$user->id;
        $o_p->order_id=$order_id;
        $o_p->pay_type=$pay_type;
        $o_p->amount=$order_amount;
        $o_p->status=1;
        $o_p->create_by=$sc_user_id;
        $o_p->tran_no=$tran_no;
        $o_p->create_type=$create_type;
        $o_p->implement_time=Common::currentTimeString();
        $o_p->save();
        if($source==1){//如果是系统 支付
        	switch ($pay_type) {
		        case 1://银行卡
		        case 2://支付宝
		        case 3://微信
		        case 7://现金
		        case 11://线下支票
		            //记录用户充值 不记录充值记录  只记录流水
		            Account::record($user->id,$order->shop_id,1,$tran_no,1,123,$order_amount,'套餐卡订单结算充值,订单号:'.$order->order_id);
		            //记录用户支出
		            Account::record($user->id,$order->shop_id,1,$tran_no,2,223,$order_amount,'套餐卡订单结算支出,订单号:'.$order->order_id);
		            //记录公司账户收入
		            Account::record_base('1',$tran_no,1,123,$order_amount,'套餐卡订单结算收入,订单号:'.$order->order_id);
		            //记录订单账务关系
		            ServiceCardOrderAccount::insert(array('order_id' => $order->order_id,'tran_no' => $tran_no,));
		            break;
		        case 8://个人余额 暂时不判断 因为个人 余额现在都为空 新版本判断用户余额
                    $uad_balance=UserAccountDeatails::where("user_id",$user->id)->whereIn("acount_type",array(1,2))->sum("balance");
		              	if(($uad_balance) >= $order_amount){
			                $arr=AcountUserRecharge::getUseRecharge($order->shop_id,$user->id,$order_amount,2,"asc");
			                if(sizeof($arr)>0){
			                  foreach ($arr as $_arr) {
			                    //记录了用户的充值消费记录
			                    $aurs=new AcountUserRechargeSpend;
			                    $aurs->aurr_id=$_arr->id;
			                    $aurs->user_id=$order->user_id;
			                    $aurs->buss_id=$o_p->id;
			                    $aurs->type=8;//套餐卡订单消费
			                    $aurs->amount=$_arr->user_amount;
			                    $aurs->status=1;
			                    $aurs->tran_no=$tran_no;
			                    $aurs->shop_id=$order->shop_id;
			                    $aurs->implement_time=date("Y-m-d H:i:s",time());
			                    $aurs->save();
			                    //更改充值记录消费的记录
			                    AcountUserRecharge::where('id',$_arr->id)->update(array('current_amount'=> $_arr->current_amount -$_arr->user_amount,));
			                    //记录个人 各种账户余额
			                    Account::record($user->id,$_arr->shop_id,$_arr->acount_type,$tran_no,2,223,$_arr->user_amount,'套餐卡订单结算支出,订单号:'.$order->order_id);
			                    //记录公司账户收入
			                    $base_acount_num=$_arr->acount_type==1?1:3;//如果用的现金账户 计入企业现金帐 如果是虚拟充值记录
			                    Account::record_base($base_acount_num,$tran_no,1,123,$_arr->user_amount,'套餐卡订单结算收入,订单号:'.$order->order_id);
			                  }
			                  ServiceCardOrderAccount::insert(array('order_id' => $order->order_id,'tran_no' => $tran_no,));
	                          // app 微站下单 生成相关套餐卡信息
	                          if(in_array($order->order_source,array(2,10))){
	                            ServiceCardDetailPack::createServiceCardDetail($order->order_id);
	                          }
			                }else{
			                  	DB::rollback();
			                  	$response = Lang::get("scs_error.order_user_notpay_40039");
			                  	return $response;
			                }
		              	}else{
		              		Log::info(1);
			                DB::rollback();
			                $response = Lang::get("scs_error.order_user_notpay_40039");
			                return $response;
		              	}
		            break;
		        case 6://企业挂账
	            	$c=Companys::find($user->id);
		            $check=Companys::accountDayStatus($c);
		            if($check["day_status"]=='逾期（禁止挂帐）'){
		              DB::rollback();
		              $response = Lang::get("scs_error.order_user_notpay_40111");
		              return $response;
		            }
		            $uad=UserAccountDeatails::where("user_id",$user->id)->where("acount_type",3)->first();
		            if(($uad->balance + $uad->credit) > $order_amount){
		              //挂账 只记录用户虚拟账户支出 挂账收回时候 记录平台收入  挂账退货 没收回退货会用户帐 ，收回之后退货，记录不回用户帐记录企业支出
		              //挂账账户是 平台门店传 0
		              Account::record($user->id,0,3,$tran_no,2,223,$order_amount,'套餐卡订单结算支出,订单号:'.$order->order_id);
		              ServiceCardOrderAccount::insert(array('order_id' => $order->order_id,'tran_no' => $tran_no,));
		            }else{
		                DB::rollback();
		                $response = Lang::get("scs_error.order_user_notpay_40039");
		                return $response;
		            }
		            break;
		        default:
		            # code...
		            break;
	        }
        }else if($source==2){
            $mpd=MaintenancePosDevice::where("id",$driver_id)->where('shop_id',$order->shop_id)->where('status',1)->first();
            if(is_null($mpd)){
              DB::rollback();
              $response = Lang::get("scs_error.order_pay_driver_error_40116");
              return $response;
            }
            $call_scan=($pay_type==20?1:0);
          	$temp_pay_type=($pay_type==20?0:$pay_type);
            //调用智能pos 支付
            $w=WposRecord::prepareOrder(5,$order_id,$o_p->id,$order_amount,$user->id,$order->shop_id,$mpd->device_no,$sc_user_id,$temp_pay_type,$call_scan);
            if($w){
              ServiceCardOrderPayRecord::where("id",$o_p->id)->update(array("status"=>5,"sources"=>2,"implement_time"=>null,"tran_no"=>''));
            }else{
              ServiceCardOrderPayRecord::where("id",$o_p->id)->update(array("status"=>2,"sources"=>2,"implement_time"=>null,"tran_no"=>''));
              $response = Lang::get("scs_error.order_pay_driver_error_40116");
              return $response;
            }
            $order_amount=0;//修改支付金额为0 回调产生才算是支付完成
        }else{
        	//微信支付
            $order_amount=0;//修改支付金额为0 回调产生才算是支付完成
            $w=WeixinRecord::wx_prepareOrder(5,$order_id,$o_p->id,$order_amount,$user->id,$order->shop_id,$sc_user_id);
            if($w){
                ServiceCardOrderPayRecord::where("id",$o_p->id)->update(array("status"=>5,"sources"=>1,"implement_time"=>null,"tran_no"=>''));

                $op_arr=ServiceCardOrderPayRecord::where("order_id",$order->order_id)->whereIn("status",array(0,1,5))->get();
                $order->pay_amount=$order->pay_amount+$order_amount;
                $order->pay_type=sizeof($op_arr)==1?$pay_type:9;
                $order->save();
                return array('code' => 0, 'msg' => 'ok', 'result' => array("order_id"=>$order->order_id,'wx_record_id'=>$w));
            }else{
                ServiceCardOrderPayRecord::where("id",$o_p->id)->update(array("status"=>2,"sources"=>1,"implement_time"=>null,"tran_no"=>''));
                $response = Lang::get("error.service_card_wx_pay_error_95006");
                return $response;
            }
        }
        $op_arr=ServiceCardOrderPayRecord::where("order_id",$order->order_id)->whereIn("status",array(0,1,5))->get();
        $order->pay_amount=$order->pay_amount+$order_amount;
        $order->pay_type=sizeof($op_arr)==1?$pay_type:9;
        $order->save();
        return array('code' => 0, 'msg' => 'ok', 'result' => array("order_id"=>$order->order_id));
      });

    }

     /**
      * @Author:      lyt
      * @DateTime:  2017-07-31 13:46:46
      * @Description: 用于撤销一个支付记录
      */
    public static function cancel($order_id,$op_id,$sc_user_id,$create_type){
      return DB::transaction(function () use ($order_id,$op_id,$sc_user_id,$create_type) {
        $order = ServiceCardOrder::where("order_id",$order_id)->lockForUpdate()->first();
        $op=ServiceCardOrderPayRecord::find($op_id);

        $tran_no = date('YmdHis',time()).Common::generateCode(8);
        //验证完成订单支付
        $o_pu=new ServiceCardOrderPayUndoRecord;
        $o_pu->opr_id=$op_id;
        $o_pu->order_id=$order_id;
        $o_pu->pay_type=$op->pay_type;
        $o_pu->amount=$op->amount;
        $o_pu->status=1;
        $o_pu->create_by=$sc_user_id;
        $o_pu->tran_no=$tran_no;
        $o_pu->create_type=$create_type;
        $o_pu->implement_time=Common::currentTimeString();
        $o_pu->save();
        if($op->sources==2){//如果是调用pos
        	$wr=WposRecord::where("type",5)->where("buss_id",$op->id)->first();
        	$p_r=Pos::statusOrder($wr->id);
		    if($p_r->status==0){
		        if($p_r->data->trade_status=="REFUND"&&$p_r->data->refund_amount==$op->amount){
			        ServiceCardOrderPayUndoRecord::where("id",$o_pu->id)->update(array("status"=>1,"sources"=>2,"tran_no"=>$tran_no,"implement_time"=>Common::currentTimeString()));
			        $wr->trade_status="REFUND";
			        $wr->pay_info=$p_r->data->pay_info;
			        $wr->return_amont=$op->amount;
			        $wr->save();
			        Account::record($order->user_id,$order->shop_id,1,$tran_no,1,124,$op->amount,'套餐卡订单结算撤销收入,订单号:'.$order->order_id);
			          //记录用户收入
			        Account::record($order->user_id,$order->shop_id,1,$tran_no,2,224,$op->amount,'套餐卡订单结算撤销支出,订单号:'.$order->order_id);
			          //记录公司账户支出
			        Account::record_base('1',$tran_no,2,224,$op->amount,'套餐卡订单结算撤销支出,订单号:'.$order->order_id);
			        ServiceCardOrderAccount::insert(array('order_id' => $order->order_id,'tran_no' => $tran_no,));
			        $op->status=6;
			        $op->save();
			        $order->pay_amount=$order->pay_amount-$op->amount;
			        $order->save();
			        return array('code' => 0, 'msg' => 'ok', 'result' => array("order_id"=>$order->order_id));
		        }
	      	}
          	$p_r=Pos::refundOrder($wr->device_en,$wr->cashier_trade_no);
          	if($p_r->status==0){
	            ServiceCardOrderPayUndoRecord::where("id",$o_pu->id)->update(array("status"=>0,"sources"=>2,"tran_no"=>"","implement_time"=>null));
	            ServiceCardOrderPayRecord::where("id",$op_id)->update(array("status"=>7));
          	}else{
          		DB::rollback();
          		$response=Lang::get("scs_error.user_not_car_cancel_error_40117");
          		$response["msg"]=$response["msg"].$p_r->info;
            	return $response;
          	}
        }else{
        	switch ($op->pay_type) {
	          	case 1://银行卡
	          	case 2://支付宝
		        case 3://微信
	          	case 7://现金
	          	case 11://线下支票
	          		Account::record($order->user_id,$order->shop_id,1,$tran_no,1,124,$op->amount,'套餐卡订单结算撤销收入,订单号:'.$order->order_id);
	                //记录用户收入
	                Account::record($order->user_id,$order->shop_id,1,$tran_no,2,224,$op->amount,'套餐卡订单结算撤销支出,订单号:'.$order->order_id);
	                //记录公司账户支出
	                Account::record_base('1',$tran_no,2,224,$op->amount,'套餐卡订单结算撤销支出,订单号:'.$order->order_id);

		            ServiceCardOrderAccount::insert(array('order_id' => $order->order_id,'tran_no' => $tran_no,));
	            	break;
	          	case 8://个人余额 暂时不判断 因为个人 余额现在都为空 新版本判断用户余额
		            $arr=AcountUserRechargeSpend::getUseRecharge($op->id,$op->amount,8);
		                if(sizeof($arr)>0){
		                    foreach ($arr as $_arr) {
			                    //记录了用户消费退款记录
			                    $aurs=new AcountUserRechargeSpendRe;
			                    $aurs->aurr_id=$_arr->aurr_id;
			                    $aurs->user_id=$order->user_id;//谁使用
			                    $aurs->aurr_sp_id=$_arr->id;
			                    $aurs->buss_id=$o_pu->id;
			                    $aurs->type=5;//套餐卡支付撤销 类型
			                    $aurs->amount=$_arr->user_amount;
			                    $aurs->status=1;
			                    $aurs->tran_no=$tran_no;
			                    $aurs->shop_id=$order->shop_id;
			                    $aurs->implement_time=date("Y-m-d H:i:s",time());
			                    $aurs->save();
			                    //更改充值记录
			                    DB::update('update acount_user_recharge_record set current_amount = current_amount+? where id = ?', array($_arr->user_amount,$_arr->aurr_id));
			                    //更改充值记录消费记录
			                    AcountUserRechargeSpend::where('id',$_arr->id)->update(array('return_amount'=> $_arr->return_amount +$_arr->user_amount,));
			                    //记录个人 各种账户余额
			                    $sac=AcountUserRecharge::find($_arr->aurr_id);
			                    Account::record($order->user_id,$sac->shop_id,$_arr->acount_type,$tran_no,1,124,$_arr->user_amount,'套餐卡订单结算撤销收入,订单号:'.$order->order_id);
			                    //记录公司账户支出
			                    $base_acount_num=$_arr->acount_type==1?1:3;//如果用的现金账户 计入企业现金帐 如果是虚拟充值记录
			                    Account::record_base($base_acount_num,$tran_no,2,224,$_arr->user_amount,'套餐卡订单结算撤销支出,订单号:'.$order->order_id);
		                    }
		                    ServiceCardOrderAccount::insert(array('order_id' => $order->order_id,'tran_no' => $tran_no,));
		                }else{
		                    DB::rollback();
		                    $response = Lang::get("scs_error.order_user_notpay_40039");
		                    return $response;
		                }
	            	break;
	            case 6://企业挂账
		            Account::record($order->user_id,0,3,$tran_no,1,124,$op->amount,'套餐卡订单结算撤销收入,订单号:'.$order->order_id);
                	ServiceCardOrderAccount::insert(array('order_id' => $order->order_id,'tran_no' => $tran_no,));
		            break;
	          	default:
		            # code...
		            break;
	        }
	        $op->status=6;
	        $op->save();
	        $order->pay_amount=$order->pay_amount-$op->amount;
	        $order->save();
        }
        return array('code' => 0, 'msg' => 'ok', 'result' => array("order_id"=>$order->order_id));
      });

    }

    /**
     * @Author:      lyt
     * @DateTime:  2017-06-23 15:15:32
     * @Description: 用于取消一个撤销中的 记录 也就是取消撤销
     */
    public static function cancelCanceIn($order_id,$op_id,$sc_user_id,$create_type){
      return DB::transaction(function () use ($order_id,$op_id,$sc_user_id,$create_type) {
      	$tran_no = date('YmdHis',time()).Common::generateCode(8);
        $order = ServiceCardOrder::where("order_id",$order_id)->lockForUpdate()->first();
        $op=ServiceCardOrderPayRecord::find($op_id);
        if($op->sources==2){//如果是调用pos
        	$wr=WposRecord::where("type",5)->where("buss_id",$op->id)->first();
        	$p_r=Pos::statusOrder($wr->id);
		    if($p_r->status==0){
		        if($p_r->data->trade_status=="REFUND"&&$p_r->data->refund_amount==$op->amount){//如果已经撤销
			        ServiceCardOrderPayUndoRecord::where("opr_id",$op_id)->update(array("status"=>1,"sources"=>2,"tran_no"=>$tran_no,"implement_time"=>Common::currentTimeString()));
			        $wr->trade_status="REFUND";
			        $wr->pay_info=$p_r->data->pay_info;
			        $wr->return_amont=$op->amount;
			        $wr->save();
			        Account::record($order->user_id,$order->shop_id,1,$tran_no,1,124,$op->amount,'套餐卡订单结算撤销收入,订单号:'.$order->order_id);
			          //记录用户收入
			        Account::record($order->user_id,$order->shop_id,1,$tran_no,2,224,$op->amount,'套餐卡订单结算撤销支出,订单号:'.$order->order_id);
			          //记录公司账户支出
			        Account::record_base('1',$tran_no,2,224,$op->amount,'套餐卡订单结算撤销支出,订单号:'.$order->order_id);
			        OrderAccount::insert(array('order_id' => $order->order_id,'tran_no' => $tran_no,));
			        $op->status=6;
			        $op->save();

			        $order->pay_amount=$order->pay_amount-$op->amount;
			        $order->save();
			        return array('code' => 0, 'msg' => 'ok', 'result' => array("order_id"=>$order->order_id));
		        }else if($p_r->data->trade_status=="PAY"){//说明订单还没撤销
		        	ServiceCardOrderPayUndoRecord::where("opr_id",$op_id)->update(array("status"=>2,"sources"=>2,"tran_no"=>"","implement_time"=>null));
	            	ServiceCardOrderPayRecord::where("id",$op_id)->update(array("status"=>1));
	            	return array('code' => 0, 'msg' => 'ok', 'result' => array("order_id"=>$order->order_id));
		        }
	      	}
        }
        return Lang::get("scs_error.order_pay_error_40122");
      });
    }

    /**
     * @Author:      lyt
     * @DateTime:  2017-06-23 14:12:00
     * @Description: 用于取消一个支付中的记录
     */
    public static function cancelPayIn($order_id,$op_id){
      return DB::transaction(function () use ($order_id,$op_id) {
        $order = ServiceCardOrder::where("order_id",$order_id)->lockForUpdate()->first();
        $op=ServiceCardOrderPayRecord::find($op_id);
        if($op->sources==2){//如果是调用pos 现在只有这一种哦
        	$wr=WposRecord::where("type",5)->where("buss_id",$op->id)->first();
        	//查询订单状态
        	$p_r=Pos::statusOrder($wr->id);
		    if($p_r->status==0){ //订单存在
		        if($p_r->data->trade_status=="CLOSED"){//如果交易关闭了
			        $wr->cashier_trade_no=$p_r->data->cashier_trade_no;
		            $wr->mcode=$p_r->data->mcode;
		            $wr->device_en=$p_r->data->device_en;
		            $wr->trade_status=$p_r->data->trade_status;
		            $wr->pay_info=$p_r->data->pay_info;
		            $wr->attach=isset($p_r->data->attach)?$p_r->data->attach:"";
		            $wr->buyer=isset($p_r->data->buyer)?$p_r->data->buyer:"";
		            $wr->thirdSerialNo=isset($p_r->data->thirdSerialNo)?$p_r->data->thirdSerialNo:"";
		            $wr->terminalNo=isset($p_r->data->terminalNo)?$p_r->data->terminalNo:"";
		            $wr->vouchNo=isset($p_r->data->vouchNo)?$p_r->data->vouchNo:"";
		            $wr->batchNo=isset($p_r->data->batchNo)?$p_r->data->batchNo:"";
		            $wr->cardType=isset($p_r->data->cardType)?$p_r->data->cardType:"";
			        $wr->save();
			        $op->status=4;
			        $op->save();
			        $result = array('code' => 0, 'msg' => 'ok', 'result' => array("order_id"=>$order->order_id));
		        }else{ //交易其他状态
                    $result = Lang::get("scs_error.order_pay_error_40121");
                }
	      	}elseif($p_r->status==1004){ //订单不存在
		        //查询消息推送情况
                $p_seq = Pos::statusPush($wr->seq_no);
                if($p_seq->status == 0){ //查询成功
                    if($p_seq->data->delivery == 1){ //送达
                        //查询订单状态
                        sleep(11);
                        $p_r=Pos::statusOrder($wr->id);
                        if($p_r->status==0){ //订单存在
                            if($p_r->data->trade_status=="CLOSED"){//如果交易关闭了
                                $wr->cashier_trade_no=$p_r->data->cashier_trade_no;
                                $wr->mcode=$p_r->data->mcode;
                                $wr->device_en=$p_r->data->device_en;
                                $wr->trade_status=$p_r->data->trade_status;
                                $wr->pay_info=$p_r->data->pay_info;
                                $wr->attach=isset($p_r->data->attach)?$p_r->data->attach:"";
                                $wr->buyer=isset($p_r->data->buyer)?$p_r->data->buyer:"";
                                $wr->thirdSerialNo=isset($p_r->data->thirdSerialNo)?$p_r->data->thirdSerialNo:"";
                                $wr->terminalNo=isset($p_r->data->terminalNo)?$p_r->data->terminalNo:"";
                                $wr->vouchNo=isset($p_r->data->vouchNo)?$p_r->data->vouchNo:"";
                                $wr->batchNo=isset($p_r->data->batchNo)?$p_r->data->batchNo:"";
                                $wr->cardType=isset($p_r->data->cardType)?$p_r->data->cardType:"";
                                $wr->save();
                                $op->status=4;
                                $op->save();

                                $result = array('code' => 0, 'msg' => 'ok', 'result' => array("order_id"=>$order->order_id));
                            }else{ //交易其他状态
                                $result = Lang::get("scs_error.order_pay_error_40121");
                            }
                        }elseif($p_r->status==1004){//订单不存在
                            //关闭订单
                            $op->status=4;
                            $op->save();
                            $result = array('code' => 0, 'msg' => 'ok', 'result' => array("order_id"=>$order->order_id));
                        }else{
                            $result = Lang::get("scs_error.order_pay_error_40121");
                        }
                    }elseif($p_seq->data->delivery == 0){ //未送达
                        //报警
                        $phones = Config::get('config.notify_phone');
                        $content = '订单['.$order_id.']取消失败，pos订单不存在且推送未送达，请及时处理。';
                        foreach ($phones as $_phone){
                            Sms::send_message('010',$_phone,$content);
                        }
                        $result = Lang::get("scs_error.order_pay_error_40121");
                    }else{
                        //报警
                        $phones = Config::get('config.notify_phone');
                        $content = '订单['.$order_id.']取消失败，pos订单不存在且推送状态未知，请及时处理。';
                        foreach ($phones as $_phone){
                            Sms::send_message('010',$_phone,$content);
                        }
                        $result = Lang::get("scs_error.order_pay_error_40121");
                    }
                }else{ //查询不成功
                    //报警
                    $phones = Config::get('config.notify_phone');
                    $content = '订单['.$order_id.']取消失败，pos订单不存在且推送状态查询失败，请及时处理。';
                    foreach ($phones as $_phone){
                        Sms::send_message('010',$_phone,$content);
                    }
                    $result = Lang::get("scs_error.order_pay_error_40121");
                }
            }else{ //订单其他状态
                $result = Lang::get("scs_error.order_pay_error_40121");
            }
        }
        return $result;
      });
    }
}